﻿<!DOCTYPE html>
<html>
<head>
<!----------------------------------------------------------

	Copyright (c) 2015 Jean-Marc VIGLINO,
	released under CeCILL-B (french BSD like) licence: http://www.cecill.info/

------------------------------------------------------------>
	<title>ol-ext: Globe control</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

	<!-- jQuery -->
	<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>

	<!-- Openlayers -->
    <link rel="stylesheet" href="https://openlayers.org/en/latest/css/ol.css" />
	<script type="text/javascript" src="https://openlayers.org/en/latest/build/ol.js"></script>
	<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL,Object.assign"></script>
	
	<!-- ol-ext -->
    <link rel="stylesheet" href="../../dist/ol-ext.css" />
	<script type="text/javascript" src="../../dist/ol-ext.js"></script>

	<link rel="stylesheet" href="../style.css" />

</head>
<body>
	<a href="https://github.com/Viglino/ol-ext" class="icss-github-corner"><i></i></a>

	<a href="../../index.html">
		<h1>ol-ext: Globe control</h1>
	</a>
	<div class="info">
		The <i>ol.control.Globe</i> add a small globe on the map to display a position marker</i>.
	</div>

	<!-- the map -->
	<div id="map" style="width:600px; height:400px;"></div>

	<div class="options">
		Layer: 
		<select onchange="setOVLayer(this)">
			<option value="0" selected="selected">Vector</option>
			<option value="1">OSM</option>
			<option value="2">Stamen</option>
			<option value="3">Mapbox</option>
		</select>
		<br />
		<input id="follow" type="checkbox" onchange="ov.set('follow', $(this).prop('checked'));" /><label for="follow"> follow (when panning the map)</label>
		<br />
		Go to:
		<button onclick="ov.setCenter([260516, 6253858]);">Paris</button>
		<button onclick="ov.setCenter([-8238435, 4970406]);">New-York</button>
		<button onclick="ov.setCenter([3120267, -3019639]);">Johannesburg</button>
		<button onclick="ov.setCenter([12946521, 4856111]);">Beijing</button>
		<button onclick="ov.setCenter([4117313, 7488805]);">Moscow</button>
		<button onclick="ov.setCenter([15519012, 4245268]);">Tokyo</button>
		<button onclick="ov.setCenter([16823948, -4007527]);">Sydney</button>
	</div>

	<script type="text/javascript">
		// The map
		var map=new ol.Map
			({
				target: 'map',
				view: new ol.View
				({	zoom: 5,
					center: [270148, 6247782]
				}),
				layers: [ new ol.layer.Tile({ source: new ol.source.Stamen({ layer: 'watercolor' }) }) ]
			});


		// GeoJSON layer
		var style = function(f)
		{	return [new ol.style.Style ({
			  fill: new ol.style.Fill({
				 color: (f.get('iso')=="US") ? 'red' : '#369'
			   })                                
			})];
		}
		var vector = new ol.layer.Vector(
		{	source: new ol.source.Vector(
				{	url: '../data/worldpt.json',
					projection: 'EPSG:3857',
					format: new ol.format.GeoJSON()
				}),
			style: style
		});
		// Layers for the overview
		var layers2 =
		[	vector,
			new ol.layer.Tile({	source: new ol.source.OSM()	}),
			new ol.layer.Tile(
				{	source: new ol.source.Stamen({
					layer: 'toner'
				  })
				}),
			new ol.layer.Tile(
			{	source: new ol.source.XYZ({
					url: 'https://{a-d}.tiles.mapbox.com/v3/mapbox.natural-earth-2/{z}/{x}/{y}.png'
    			})
			}),
			/*
			new ol.layer.Tile({
				name: "Occupy streets",
    			source: new ol.source.XYZ(
				{	url: 'https://{a-d}.tiles.mapbox.com/v3/occupy.occupy-streets/{z}/{x}/{y}.png'
    			})
			}),
			new ol.layer.Tile({
				name: "pirate",
    			source: new ol.source.XYZ(
				{	url: 'https://{a-d}.tiles.mapbox.com/v3/aj.Sketchy2/{z}/{x}/{y}.png'
    			})
			}),
			new ol.layer.Tile({
				name: "Occupy streets",
    			source: new ol.source.XYZ(
				{	url: 'https://{a-d}.tiles.mapbox.com/v3/occupy.occupy-streets/{z}/{x}/{y}.png'
    			})
			}),
			*/
		];

		// New control on the map
		var ov = new ol.control.Globe(
			{	layers: layers2,
				follo: $("#follow").prop("checked"),
				align: $("#align").val(),
				panAnimation: "elastic"
			});
		map.addControl(ov);

		// Options changes
		function setOVLayer (e)
		{	var l = ov.getGlobe().getLayers().getArray()
			for (var i=0; i<l.length; i++) l[i].setVisible(false);
			l[$(e).val()].setVisible(true);
		}
		setOVLayer(".options > select");
	</script>

</body>
</html>